<template>
  <view class="container p-content">
    <view>
      <uni-file-picker limit="5" file-mediatype="all" title="最多选择5个文件"
                       v-model="fileList"
                       @select="select"
                       @delelte="deleteFile"
      ></uni-file-picker>
    </view>
  </view>
</template>

<script>
import uniFilePicker from "@/uni_modules/uni-file-picker/components/uni-file-picker/uni-file-picker.vue";
import {FileUtils} from "@/util/uniUtils";
import {getFileAccessHttpUrl, uploadAction} from "@/util/api";
export default {
  name: "uniUpload",
  components: {
    uniFilePicker,
  },
  props:{
    value: {
      type: Array,
      default: () => []
    },
  },
  data(){
    return {
      fileList: this.value
    }
  },
  methods: {
    async select(e) {
      console.log(e)
      let {tempFiles} = e
      for (let t of tempFiles) {
        let {path,name,uuid} = t
        if (FileUtils.isImg(name)){
          //如果是图片,则进行压缩
          // path = await FileUtils.compressImage(path)
        }
        //上传文件
        path = await uploadAction(path)
        console.log("图片路径->",path)
        this.fileList.push({
          name,
          url:getFileAccessHttpUrl(path),
          extname:FileUtils.getSuffix(name),
          uuid,
        })
      }
    },
    deleteFile(e){
      console.log("删文件啦",e)
    }
  },
  watch:{
    fileList1(newVal) {
      this.$emit('input', newVal)
    },
  }
}
</script>



<style scoped lang="scss">

</style>
